package com.dengqi.mymodule.activity.chenj;


import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dengqi.mymodule.R;
import com.dengqi.mymodule.fragment.BaseFragment;
import com.dengqi.mymodule.tools.StatusBarUtils;

import androidx.annotation.Nullable;

/**
 * Created by dell on 2018/6/15
 */

public class NavFragment extends BaseFragment {

    private TextView textView;
    private LinearLayout layoutTitle;

    public static NavFragment newInstance(String title) {
        NavFragment fragment = new NavFragment();
        Bundle args = new Bundle();
        args.putString("title", title);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_nav, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        textView = view.findViewById(R.id.textView);
        layoutTitle = view.findViewById(R.id.layout_title);

        Bundle bundle = getArguments();
        String title = null;
        if (bundle != null) {
            title = bundle.getString("title");
            textView.setText(title);
        }

        if ("首页".equals(title)) {
            layoutTitle.setBackgroundResource(R.color.black);
            StatusBarUtils.StatusBarDarkMode(getActivity());
        } else if ("类型".equals(title)) {
            layoutTitle.setBackgroundResource(R.color.red);
            StatusBarUtils.StatusBarDarkMode(getActivity());
        } else if ("发现".equals(title)) {
            layoutTitle.setBackgroundResource(R.color.green);
            StatusBarUtils.StatusBarDarkMode(getActivity());
        } else if ("我的".equals(title)) {
            layoutTitle.setBackgroundResource(R.color.white);
            int res = StatusBarUtils.StatusBarLightMode(getActivity());
            if(res ==0){
                layoutTitle.setBackgroundResource(R.color.red);
            }
        }


        initWindow();

    }

    public void initWindow() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            //5.0以上的沉浸式
            //让应用主题内容占用系统状态栏的空间,注意:下面两个参数必须一起使用 stable 牢固的
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            //设置状态栏颜色为透明
            getActivity().getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            //4.4以上的沉浸式
            getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

}
